package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.User;
import com.hengxinguotong.zhihuichengjian.utils.Utils;
import com.hengxinguotong.zhihuichengjian.widget.view.GlideRoundTransform;

import java.util.List;

public class AddGroupTopAdapter extends
        RecyclerView.Adapter {
    private Context context;
    private List<User> infos;

    public AddGroupTopAdapter(Context context, List<User> infos) {
        this.context = context;
        this.infos = infos;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_addgroup_top, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof ViewHolder) {
            ViewHolder viewHolder = (ViewHolder) holder;
            User user=infos.get(position);
            String headPortrait = user.getHeadPortrait();
            if(!Utils.isEmpty(headPortrait)){
                headPortrait = headPortrait.substring(0, headPortrait.lastIndexOf(".")) + "_100x100" + headPortrait.substring(headPortrait.lastIndexOf("."));
            }
            Glide.with(context).load(headPortrait).placeholder(R.mipmap.icon_avater_defalut).error(R.mipmap.icon_avater_defalut).transform(new GlideRoundTransform(context, 10)).into(viewHolder.avaterImageView);
        }
    }

    @Override
    public int getItemCount() {
        return infos.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        private final ImageView avaterImageView;

        public ViewHolder(View itemView) {
            super(itemView);
            avaterImageView = (ImageView) itemView.findViewById(R.id.item_avater);

        }
    }

}
